﻿using Common;
using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class UserInfoBLL
    {

        //0:登录成功   -1:登录失败     1：非经理      
        public int UserInfoLogin(UserInfo userInfo)
        {
            //调用DAL
            UserInfoDAL userInfoDAL = new UserInfoDAL();

            //密码进行加密处理
            userInfo.Password = MD5Helper.GetMD5(userInfo.Password);
            //判断是否登录成功
            if (userInfoDAL.SelectUser(userInfo) == 0)
            {
                //判断是否为经理
                if (userInfo.Position == "经理")
                {
                    return 0;
                }
                else return 1;
            }
            else return -1;

            
        }

        
        public DataTable UserInfoSelect()
        {
            //调用DAL展示数据
            UserInfoDAL userInfoDAL = new UserInfoDAL();
            return userInfoDAL.ShowUser();
        }

        public int ADD(UserInfo userInfo)
        {
            //调用DAL添加数据
            UserInfoDAL userInfoDAL = new UserInfoDAL();

            //将注册的密码进行加密处理
            userInfo.Password = MD5Helper.GetMD5(userInfo.Password);

            return userInfoDAL.InsertUser(userInfo);
        }

        public int UPDATE(UserInfo userInfo)
        {
            //调用DAL更新数据
            UserInfoDAL userInfoDAL = new UserInfoDAL();

            //密码进行加密处理
            userInfo.Password = MD5Helper.GetMD5(userInfo.Password);
            return userInfoDAL.UpdateUser(userInfo);
        }

        public int DELETE(int uid)
        {
            //调用DAL删除数据
            UserInfoDAL userInfoDAL = new UserInfoDAL();

            return userInfoDAL.DeleteUser(uid);
        }
    }
}
